10. Lab III: Build a Dog REST API (Annotations II)

Lab III: Build a Dog REST API

Here, we'll finish off this lesson's lab, creating a REST API that returns a list of dogs from an embedded H2 in memory database. This time, you'll add a repository & service, complete the DogController you started earlier, make sure errors are handled, and then create a .sql file for some example dog data.

Annotations Part II

  • Step 1: Create a repository that extends CrudRepository for creating, reading, updating, and deleting Dog objects.

  • Step 2: Create a dog service that performs the following operations:

    • retrieveDogBreed
    • retrieveDogBreedById
    • retrieveDogNames

You may want to check out this Stack Overflow post for one possible way you might help implement these operations by adjusting the repository created in Step 1.

  • Step 3: Update the web controller using @RestController that handles requests for retrieving:

    • a list of Dog breeds
    • a list of Dog breeds by Id
    • a list of Dog names
  • Step 4: Make sure errors are handled appropriately.

    • if an id is requested that doesn’t exist, appropriately handle the error
  • Step 5: Create a data.sql file to create sample dog data in the database.

If you aren't familiar with SQL, take a look back at Kesha's file from the Location API case study.

  • Step 6: Check that you are able to access your API.

Build a Dog REST API Lab

Task List:

Task Feedback:

Great! You've now built your own functioning REST API. Soon, you'll develop a similar GraphQL API and microservice!